<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>转优车管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label {
            width: 70px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">支付表号</div>
                    <div class="field">
                        <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="contNo" id="contNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">是否可过户</div>
                    <div class="field">
                        <input name="isAssign" id="isAssign" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">流程节点</div>
                    <div class="field">
                        <input name="taskDefKey" id="taskDefKey" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="btnsBox formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round"></i>查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round"></i>清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>

                <!-- 逾期提醒 -->
                <div style="float:right; margin-top:15px; margin-right:40px;">
					<span>
						<font color="blue" style="font-size: 13px;"><i class="ico_flasher_blue"></i>资料上传<7天</font>
					</span>
                    <span>
						<font color="red" style="font-size: 13px;"><i class="ico_flasher"></i>资料上传<3天</font>
					</span>
                </div>
            </div>
        </form>
    </div>

    <div id="ligergrid" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var basePath = '<%=path%>';
    var grid = null;
    $(function () {
        // 是否可过户
        $("#isAssign").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            data: ${isAssign}
        });

        $("#taskDefKey").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            data: ${taskDefKeyDic}
        });

        grid = $("#ligergrid").ligerGrid({
            url: basePath + '/ass/dealcar/manage/loadListData.do',
            parms: {},
            method: 'get',
            columns: [
                {display: '<span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="资料上传限时提醒"></span>',
                    name: '', minWidth: 30, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if (rowdata.taskDefKey == 'FLOW_0000_020_001_001' || rowdata.taskDefKey == 'FLOW_0000_020_001_002'
                            || rowdata.taskDefKey == 'FLOW_0000_020_001_004' || rowdata.taskDefKey == 'FLOW_0000_020_001_005') {
                            return formatTip(rowdata, index, value);
                        }
                    }
                },
                {display: '合同号', name: 'contNo', minWidth: 140, align: 'center', enabledSort: false},
                {display: '支付表号', name: 'paySchNo', width: 190, align: 'center', enabledSort: false},
                {display: '客户名称', name: 'cstNm', width: 100, align: 'center', enabledSort: false},
                {display: '过户项目', name: 'assTransferInfoDTO.categoryNm', width: 100, align: 'center', enabledSort: false},
                {display: '过户进度', name: 'assTransferInfoDTO.scheduleNm', width: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        var show = value;
                        if (rowdata.assTransferInfoDTO == null || StringUtils.isEmpty(rowdata.assTransferInfoDTO.categoryNm)) {
                            if (rowdata.taskDefKey == 'FLOW_0000_020_001_006' || rowdata.taskDefKey == 'FLOW_0000_020_001_007'
                                || rowdata.taskDefKey == 'FLOW_0000_020_001_008') {
                                show = "未完成";
                            }
                        }
                        return show;
                    }
                },
                {display: '过户金额', name: 'assTransferInfoDTO.amount', width: 90, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return formatAmt(value);
                    }
                },
                {display: '是否可过户', name: 'isAssign', width: 80, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if (value == null) return value;
                        return value == 1 ? "是" : "否";
                    }
                },
                {display: '预计完成时间', name: 'assTransferInfoDTO.estimateTime', width: 130, align: 'center', enabledSort: false, render: renderDate2},
                {display: '流程节点', name: 'taskDefKeyNm', width: 130, align: 'center', enabledSort: false},
                {display: '流程编号', name: 'procNo', width: 170, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if (value == null || value == "") return value;
                        return '<a href="javascript:commShowFlow(' + index + ')">' + value + '</a>';
                    }
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: true,
            frozen: false
        });

        $("#searchBar").ligerForm();
        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "*Cd": " ",
                "isAssign": "",
                "taskDefKey": ""
            });
        });

    });

    function commShowFlow(rowindex) {
        var rowdata = grid.getRow(rowindex);
        var _formUrl = "/ass/assTrailCarD/toOptimalViewPage.do?viewFlag=1@@flag=6@@optimal_Id=",
            _pInstId = rowdata.procId;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {procId: _pInstId, type: "2"},
            url: basePath + '/settlement/queryFlowData.do',
            success: function (msg) {
                if (msg.success == 1) {
                    var params = "?pInsId=" + _pInstId + "&status=" + msg.data.audStsCd + "&businessKey=" + msg.data.dataId + "&formUrl=" + _formUrl;
                    Add_navTab('tab_ass_trail_flow_' + _pInstId, msg.data.pno, basePath + "/flow/flow/toFlowShowPageFowBus.do" + params);
                } else {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    function formatTip(rowdata, index, value) {
        var expireTime = rowdata.expireTime;
        if (expireTime == null || expireTime == "") return value;
        var currentSec = new Date(rowdata.currentDt).getTime() / 1000;
        var expireSec = new Date(expireTime).getTime() / 1000;
        if (currentSec > expireSec) {
            return "";
        }
        var threeDay = (60 * 60 * 24) * 3;
        var sevenDay = (60 * 60 * 24) * 7;
        var diffSec = expireSec - currentSec;
        var show = '';
        if (diffSec < threeDay) {
            show = '<i class="ico_flasher"></i>';
        } else if (diffSec < sevenDay) {
            show = '<i class="ico_flasher_blue"></i>';
        }
        return show;
    }

    function formatAmt(value) {
        if (StringUtils.isEmpty(value)) {
            return '';
        } else {
            if (value > 0) {
                return '<font color="green">&yen;' + FormatMoney(value / 100) + '</font>';
            } else if (value == 0) {
                return '&yen;' + FormatMoney(value / 100);
            } else {
                return '<font color="red">-&yen;' + FormatMoney(Math.abs(value) / 100) + '</font>';
            }
        }
    }

    //格式化时间
    function renderDate2(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
</script>
</body>
</html>
